package client.tzstore.oo.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import client.comm.commlib.R

abstract class BottomBindingDialog<V : ViewDataBinding> : Dialog {

    constructor(context: Context) : super(context, R.style.BottomDialog)

    lateinit var binding: V
    lateinit var view: View

    abstract fun getV(): Int

    open fun postBinding() {}


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = DataBindingUtil.inflate<V>(LayoutInflater.from(context), getV(), null, false) as V

        setContentView(binding.root)
        postBinding()
        window?.apply {
            setGravity(Gravity.BOTTOM)

            setLayout(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT
            )
        }
        setCanceledOnTouchOutside(true)
    }
}